//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.goldhuman.Common.Security;

import com.goldhuman.Common.Octets;

public final class HMAC_MD5Hash extends Security {
    private Octets k_opad = new Octets(64);
    private com.goldhuman.Common.Security.MD5Hash md5hash = new com.goldhuman.Common.Security.MD5Hash();

    protected HMAC_MD5Hash() {
    }

    public Object clone() {
        try {
            HMAC_MD5Hash o = (HMAC_MD5Hash)super.clone();
            (o.k_opad = (Octets)this.k_opad.clone()).reserve(64);
            o.md5hash = (com.goldhuman.Common.Security.MD5Hash)this.md5hash.clone();
            return o;
        } catch (Exception var2) {
            return null;
        }
    }

    public void SetParameter(Octets param) {
        Octets k_ipad = new Octets(64);
        int keylen = param.size();
        if (keylen > 64) {
            Octets key = com.goldhuman.Common.Security.MD5Hash.Digest(param);
            k_ipad.replace(key);
            this.k_opad.replace(key);
            keylen = key.size();
        } else {
            k_ipad.replace(param);
            this.k_opad.replace(param);
        }

        int i;
        for(i = 0; i < keylen; ++i) {
            k_ipad.setByte(i, (byte)(k_ipad.getByte(i) ^ 54));
            this.k_opad.setByte(i, (byte)(this.k_opad.getByte(i) ^ 92));
        }

        while(i < 64) {
            k_ipad.setByte(i, (byte)54);
            this.k_opad.setByte(i, (byte)92);
            ++i;
        }

        k_ipad.resize(64);
        this.k_opad.resize(64);
        this.md5hash.Update(k_ipad);
    }

    public Octets Update(Octets o) {
        this.md5hash.Update(o);
        return o;
    }

    public Octets Final(Octets digest) {
        this.md5hash.Final(digest);
        com.goldhuman.Common.Security.MD5Hash ctx = new MD5Hash();
        ctx.Update(this.k_opad);
        ctx.Update(digest);
        return ctx.Final(digest);
    }
}
